from rest_framework import serializers

from patient.models import SourceModel, AppointmentModel, PatientModel,TriageModel,BookingModel


class SourceSerializer(serializers.ModelSerializer):
    class Meta:
        model = SourceModel
        fields = '__all__'
class AppointmentSerializer(serializers.ModelSerializer):
    class Meta:
        model = AppointmentModel
        fields = '__all__'
class PatientSerializer(serializers.ModelSerializer):
    new_source = serializers.SerializerMethodField(read_only=True)
    new_appointment = serializers.SerializerMethodField(read_only=True)
    def get_new_source(self, obj):
        return obj.source.sname
    def get_new_appointment(self, obj):
        return obj.appointment.aname
    class Meta:
        model = PatientModel
        fields = '__all__'



class TriageSerializer(serializers.ModelSerializer):
    class Meta:
        model = TriageModel
        fields = '__all__'

class BookingSerializer(serializers.ModelSerializer):
    new_source = serializers.SerializerMethodField(read_only=True)
    new_Triage = serializers.SerializerMethodField(read_only=True)
    new_appointment = serializers.SerializerMethodField(read_only=True)


    def get_new_source(self, obj):
        return obj.source.sname

    def get_new_appointment(self, obj):
        return obj.appointment.aname

    def get_new_Triage(self,obj):
        return obj.Triage.tname

    class Meta:
        model = BookingModel
        fields = '__all__'


